import { defineStore } from "pinia"
import { computed, ref } from "vue"

// 定义一个storeOne，这个名称是pinia的唯一标识，用来区分不同的store
export const useStoreOne = defineStore('storeOne', () => {
    // 定义的state
    const count = ref(0)
    const description = ref('这是componsition API 风格的一个storeOne')
    const CURRENT_ROUTE = ref({})

    const SET_CURRENT_ROUTE = (DATA: {}) => {
        CURRENT_ROUTE.value = DATA
    }

    // 定义的getter，composition API 风格的getter是计算属性
    const getCountDescription = computed(() => {
        return `${description.value}，其中一个值为${count.value}`
    })
    // 定义的action
    const actionTest = () => {
        count.value++
    }

    // pinia中所有定义的属性都要导出
    return {
        count,
        description,
        getCountDescription,
        actionTest,
        CURRENT_ROUTE,
        SET_CURRENT_ROUTE
    }
})